package com.itheima.demo;

public class QuiteSortDemo {
    public static void main(String[] args) {
        int [] arr = {6, 1, 2, 7, 9, 3, 4, 5, 10, 8};
        quitesort(arr,0,arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }

    private static void quitesort(int[] arr, int left, int right) {
        if (right < left) {
            return;
        }
        int left0 = left;
        int right0 = right;
        int baseNumber = arr[left0];
        while (left != right){
            while (arr[right] >= baseNumber && left < right){
                right--;
            }
            while (arr[left] <= baseNumber && left < right){
                left++;
            }
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
        }
        //基准数归为
        int temp = arr[left0];
        arr[left0] = arr[left];
        arr[left] = temp;
        quitesort(arr, left0, left-1);
        quitesort(arr, left+1, right0);
    }
}
